home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
basic
/
outline.lha
/
OutlineFonts
/
OutlineFonts.asc
< prev
next >
Wrap
Text File
|
1999-03-15
|
24KB
|
641 lines
; Description: Outline font test, doing everything fully, so that the
; correct engine for that font can be used to ceate the
; characters, rather than just use them as is.
;
; I had to use ASM to call the correct library routines
; for non-bullet fonts, as FDConvert only does for one
; library, not interchangable ones.
;
; Requires: amigalibs.res with OS3.1 includes (from NewCommandSet1.70)
; Probably OS3+, maybe OS2+
;
; To do: Write functions for the following:
; Use of bold, italic, underlined fonts
; Anything else that seems a good idea at the time
; Carrige returns in the print string
; Rather than copy then BltTemplate_, I need to do a fast ASM version
;
; Type: SYSTEM
;
; Author: David McMinn <dmcminn@house-of-mojo.freeserve.co.uk>
WBStartup
DEFTYPE.w
; ############################################################################
; ####################### START OF OUTLINE ROUTINES ##########################
; ############################################################################
NEWTYPE.GlyphInfo
*gi_otag.TagItem ; Pointer to the location of the otag file in memory
*gi_library.Library ; Pointer to the library used for this type of font
*gi_engine.GlyphEngine ; Pointer to the engine within the library
gi_xdpi.w ; X dpi of the target output device
gi_ydpi.w ; Y dpi of the target output device
gi_pointsize.q ; Current pointsize
gi_angle.w ; Current rotation
gi_spacewidth.l ; The width of a space in stupid measurement units
End NEWTYPE
; ----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; NAME:
; Glyph_CloseEngine
;
; SYNOPSIS:
; Glyph_CloseEngine{*gi}
;
; Glyph_CloseEngine{.GlyphInfo}
;
; FUNCTION:
; This function releases all resources that are contained within the
; GlyphInfo newtype specified in the pointer passed as a parameter.
; Specifically, this closes the glyph engine, the library it came
; from and then frees the .otag file from memory.
;
; INPUTS:
; *gi.GlyphInfo -- a pointer to a GlyphInfo newtype. It is safe to call
; this function with a NULL pointer
;
; RESULT:
; Resources are freed
;
; BUGS:
; None
;
; SEE ALSO:
; Glyph_OpenEngine
;
;-----------------------------------------------------------------------------
Statement Glyph_CloseEngine{*gi.GlyphInfo}
; If a non-NULL pointer is passed in
If *gi
; Try to free the engine
If *gi\gi_engine
; CloseEngine_ *gi\gi_engine
MOVEA.l -4(a4),a0 ; Get *gi into a0
MOVEA.l 4(a0),a6 ; Get proper library base into a6
MOVEA.l 8(a0),a0 ; Glyph Engine into a0
JSR -$24(a6) ; JSR to CloseEngine_
*gi\gi_engine = 0
End If
; Try to free the library
If *gi\gi_library
CloseLibrary_ *gi\gi_library
*gi\gi_library = 0
End If
; Try to free the otag file from memory
If *gi\gi_otag
FreeVec_ *gi\gi_otag
*gi\gi_otag = 0
End If
End If
End Statement
; ----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
; NAME:
; Glyph_OpenEngine
;
; SYNOPSIS:
; success = Glyph_OpenEngine{*gi, fontname}
;
; long = Glyph_OpenEngine{.GlyphInfo, string}
;
; FUNCTION:
; This function tries to open all the required resources for rendering
; glyphs from the specified font.
;
; INPUTS:
; *gi.GlyphInfo -- Pointer to a GlyphInfo newtype. This should not be
; initialised before calling this function, if it
; has been used before make sure you free all resources
; by calling Glyph_CloseEngine first.
; fontname$ -- The name of the font you wish to open. This is
; specified as the full path to the font and the name of it,
; minus the .otag extension, i.e. "FONTS:CGTimes"
;
; RESULT:
; On success this function returns TRUE. On failure, it will
; return FALSE.
;
; BUGS:
; None
;
; SEE ALSO:
; Glyph_CloseEngine
;
;-----------------------------------------------------------------------------
Function.l Glyph_OpenEngine{*gi.GlyphInfo,fontname$}
DEFTYPE.b *enptr ; Pointer to the start of the engine name string
DEFTYPE.l *ge ; The glyph engine for this font
DEFTYPE.s sename ; The name of the scaling engine
DEFTYPE.s selib ; The name of the library for this engine
DEFTYPE.s otpath ; The full path and name of the font + .otag
DEFTYPE.w ge_ok ; Flag to show if the glyph engine was set up OK
DEFTYPE.TagItem *otag ; Pointer to the otag data in memory
DEFTYPE.l otagsize ; Size of the .otag file for this font
DEFTYPE.w dfh_id ; The ID field from the diskfontcontents structure (.font file)
DEFTYPE.TagItem *ptr ; Working pointer, for use with the OTAG taglist
Dim tag.TagItem(3) ; The taglist used to set options in the glyph engine
; Initialise pointer to .otag file in memory
*gi\gi_otag = 0
; Try to read the font contents file (.font file) from FONTS:
If ReadFile(0,fontname$+".font")
FileInput 0
; If we could open it, read the first two bytes into a word, for recognition
ReadMem 0,&dfh_id,2
PopInput
CloseFile 0
End If
; Check if the font is an outline font
If dfh_id=#OFCH_ID
; If it is then we read the contents of the .otag file (Outline TAG file)
If ReadFile(0,fontname$+".otag")
FileInput 0
otagsize.l = Lof(0)
*gi\gi_otag = AllocVec_(otagsize, #MEMF_CLEAR|#MEMF_PUBLIC)
If(*gi\gi_otag) Then ReadMem 0,*gi\gi_otag,otagsize
PopInput
CloseFile 0
End If
End If
; If the otag file was read into memory, this pointer will be valid
; and we can process it that little bit extra (sort out OT_Indirects
; (which are ti_Datas that are supposed to be pointers, but are specified
; as offsets.
If *gi\gi_otag
If *gi\gi_otag\ti_Tag<>#OT_FileIdent OR *gi\gi_otag\ti_Data<>otagsize
; This must be the first tag and data, it is to verify that the otag file is valid
Glyph_CloseEngine{*gi}
Else
; Now we have the .otag file and it is valid, we can begin processing it
; Start from the second tag (as we know that #OT_FileIdent is the
; first tag)
*ptr = *gi\gi_otag + SizeOf.TagItem
While *ptr\ti_Tag
; For all the tags check if the indirect flag is set, and if it is
; add the base address of the data block to the tag data.
; That is because the tag data specifies an offset not an address.
If *ptr\ti_Tag & #OT_Indirect Then *ptr\ti_Data=*ptr\ti_Data+*gi\gi_otag
*ptr = *ptr + SizeOf.TagItem
Wend
End If
End If
; Return a failure if we do not have a valid outline taglist
If *gi\gi_otag=0 Then Function Return 0
; Try to get pointer to the engine name string, from the taglist
*enptr = GetTagData_(#OT_Engine, 0, *gi\gi_otag)
If *enptr=0
; If we couldn't find the name string then we need to return a
; failure
Glyph_CloseEngine{*gi}
Function Return 0
End If
; Try to get the width of a space character in ridiculous units
*gi\gi_spacewidth = GetTagData_(#OT_SpaceWidth, 0, *gi\gi_otag)
; Get the name